
cd /disk/agedisk3/medicare.work/poterba-DUA52260/jetson-dua52260/kyphon/substitutes/robustness/feout
use groupspanel_feout.dta
keep if group  == 999

merge 1:1 dt using synth_fit.dta


local treatment_period =  mofd(mdy(12, 12, 2005))
disp `treatment_period'

** Produce difference in series
gen deterrence = fit1 - out if dt >= `treatment_period'


** Time discount the difference at 10% 
local r = 1.1^(1/12)

gen deterrence_disc = deterrence*1/(`r'^(dt-`treatment_period'))
replace deterrence_disc = . if dt-`treatment_period' >= 60
count if !mi(deterrence_disc)
assert(r(N)==60)

*** Compute total
log using deterrence_feout.log, replace
preserve
collapse (sum) deterrence_disc
 summarize deterrence_disc
local deterrence = r(min)
disp `deterrence'
restore
log close 

*** Truncate graph at 5 years 
drop if dt  - `treatment_period' >= 60
summarize dt 
local minperiod = r(min)
local maxperiod = r(max)


** Settlement date:
local settlement= mofd(mdy(5,22,2008))


format dt %tm_Mon_YY
twoway (scatter pmt_amt dt, mcolor(gs5)) (line out fit1 dt, lwidth(thick thick) lcolor(navy maroon)), xline(`treatment_period') xline(`settlement', lcolor(black)) legend(order(2 "Kypho/Vertebroplasty" 3 "Synthetic Control") width(150)) xscale(range(`minperiod' `maxperiod')) xlabel(516 `treatment_period' `settlement' 612) xtitle("Month") ytitle("$/Month") graphregion(color(white)) yscale(range(-6000000 12000000)) ylabel(-5000000 "-$5 Mil" 0 "$0" 5000000 "$5 Mil" 10000000 "$10 Mil")

graph save "KyphoSubstituteOverlay_feout.gph", replace

